// tv.h -- TV and Remote classes
#ifndef TV_H_
#define TV_H_
class Remote;
class Tv
{
public:
    friend class Remote;
    enum {MinVal, MaxVal = 20};
    enum {Off, On};
    enum {Broadcast, Cable};
    enum {TV, DVD};
    // 这里的初始化数据要和私有属性的顺序保持一致，否则会报错
    Tv(int s = Off, int maxch = 25):state(s),maxchannel(maxch),
        channel(2),volume(5),mode(Cable),input(TV){};
    void onoff(){state = (state == Off) ? On : Off;}
    bool isOn(){return state == On ? true : false;}
    bool volup();
    bool voldown();
    bool channelup();
    bool channeldown();
    void set_mode(){mode = mode == Broadcast ? Cable : Broadcast;}
    void set_input(){input = input == TV ? DVD : TV;}
    void settings() const;
private:
    int state; // on or off
    int maxchannel;
    int channel; // current channel
    int volume; // current volue
    int mode; // broadcast or cable
    int input; // TV or DVD
};

class Remote {

public:
    Remote(int m = Tv::TV):mode(m){}
    void onoff(Tv & tv){tv.onoff();}
    void volup(Tv & tv){tv.volup();}
    void voldown(Tv & tv){tv.voldown();}
    void channelup(Tv & tv){tv.channelup();}
    void channeldown(Tv & tv){tv.channeldown();}
    void set_chan(Tv & tv, int c) {tv.channel = c;}
    void set_mode(Tv & tv) {tv.set_mode();}
    void set_input(Tv & tv) {tv.set_input();}
    
private:
    int mode;
};

#endif

